package spring_learn.a12;

import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.UndeclaredThrowableException;

public class Proxy$Target2 extends Proxy implements A12.foo{

    private  InvocationHandler invocationHandler;

    static final Method foo1;
    static final Method foo2;

    static {
        try {
            foo1 = A12.foo.class.getDeclaredMethod("foo1");
            foo2 = A12.foo.class.getDeclaredMethod("foo2");
        }catch (NoSuchMethodException e){
            throw new NoSuchMethodError(e.getMessage());
        }
    }

    /**
     * Constructs a new {@code Proxy} instance from a subclass
     * (typically, a dynamic proxy class) with the specified value
     * for its invocation handler.
     *
     * @param h the invocation handler for this proxy instance
     * @throws NullPointerException if the given invocation handler, {@code h},
     *                              is {@code null}.
     */
    protected Proxy$Target2(java.lang.reflect.InvocationHandler h) {
        super(h);
    }

    @Override
    public void foo1() {
        try {
            Object res = invocationHandler.invoke(this, foo1, new Object[0]);
        }catch (RuntimeException | Error e) {
            throw e;
        } catch (Throwable e) {
            throw new UndeclaredThrowableException(e);
        }
    }

    @Override
    public void foo2() {
        try {
            Object res = invocationHandler.invoke(this, foo2, new Object[0]);
        }catch (RuntimeException | Error e) {
            throw e;
        } catch (Throwable e) {
            throw new UndeclaredThrowableException(e);
        }
    }
}
